package com.example.llview;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {
    private ListView lvHome;
    private String[] title = {"小米路由器","180Hz显示器","惠普","固态硬盘","技嘉海景房","小米笔记本"};
    private String[] pra = {"74.8","529","388","93","3258","3299"};
    private int[] img = {R.drawable.img,R.drawable.img_1,R.drawable.img_2,R.drawable.img_3,R.drawable.img_4,R.drawable.img_5};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        lvHome = findViewById(R.id.lv_list);
        GoodsAdapter good = new GoodsAdapter();
        lvHome.setAdapter(good);
    }
    private class GoodsAdapter extends BaseAdapter{
        @Override
        public int getCount() {
            return title.length;
        }

        @Override
        public Object getItem(int position) {
            return title[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            View view = View.inflate(MainActivity.this, R.layout.item_layout, null);

            TextView t = view.findViewById(R.id.textView2);
            TextView price = view.findViewById(R.id.textView4);
            ImageView image = view.findViewById(R.id.imageView);

            t.setText(title[position]);
            price.setText(pra[position]);
            image.setImageResource(img[position]);

            return view;
        }
    }

}